//检查浏览器版本，兼容手机
layui.config({
  base: contextPath+'/static/layui/lay/modules/'
}).use('global');
window.global = {
  preview: function(){
    var preview = document.getElementById('LAY_preview');
    return preview ? preview.innerHTML : '';
  }()
};
//tab标签切换初始化
layui.use('element', function(){
	  var $ = layui.jquery
	  ,element = layui.element(); //Tab的切换功能，切换事件监听等，需要依赖element模块
	  //触发事件
	  var active = {
	    tabAdd: function(othis){
	      var ishave = false;
	      $("#demoTitle").find(".layui-tab-title").find("li").each(function(){
	    	  if($(this).attr("lay-id")==othis.attr("tab-id")) ishave = true;
	      });
	      if(!ishave){
		      var contentId = "tabcontent"+othis.attr("tab-id");
		      //新增一个Tab项
		      element.tabAdd('demoTitle', {
		        title: othis.html() //tab栏显示
		        ,content: " <iframe id='"+contentId+"' src=\""+othis.attr("loadurl")+"\"  frameborder=0 width=\"100%\" height=\"100%\"></iframe>"//内容显示
		        ,id: othis.attr("tab-id") //实际使用一般是规定好的id
		      });
	      }
	      element.tabChange('demoTitle', othis.attr("tab-id")); //切换到
	      $('body').removeClass('site-mobile');
	    }
	  };
	  //菜单点击触发
	  $('.site-demo-active').on('click', function(){
	    var othis = $(this), type = othis.data('type');
	    active[type] ? active[type].call(this, othis) : '';
	  });
	  //菜单首页触发，切换到首页
	  $('#admin-home-menu').on('click', function(){
	      element.tabChange('demoTitle', "admin-home"); 
	  });
});
function loginOut(){
	layer.confirm('确定推出当前用户？', {
		title:"提示",
		btn: ['确定','取消'] //按钮
	}, function(){
		$.post(contextPath+"/back/loginOut",function(data){
			if(data=="success"){
				layer.msg('退出登录成功！', {icon: 1});
			}
			location.href = contextPath+"/back/login";
		});
	}, function(){
	});
	
}